var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		pagId : 'paging',
		l_column : [ {
			colkey : "name",
			name : "名称",
			isSort:true,
		}, {
			colkey : "code",
			name : "编码",
			isSort:true,
		}, {
			colkey : "position",
			name : "排序",
			isSort:true,
		}, {
			colkey : "createTime",
			name : "创建时间",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd");
			}
		}],
		jsonUrl : rootPath + '/goods/goodsBrand/selectListByPage',
		checkbox : true,
	});
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		grid.setOptions({
			data : searchParams
		});
	});
	
	$("#addGoodsBrand").click("click", function() {
		addGoodsBrand();
	});
	$("#editGoodsBrand").click("click", function() {
		editGoodsBrand();
	});
	$("#deleteGoodsBrand").click("click", function() {
		deleteGoodsBrand();
	});
});

function addGoodsBrand() {
	pageii = layer.open({
		title : "新增品牌",
		type : 2,
		area : [ "400", "45%" ],
		content : rootPath + '/goods/goodsBrand/addOrEdit'
	});
}

function editGoodsBrand() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("只能选中一个");
		return;
	}
	pageii = layer.open({
		title : "编辑品牌",
		type : 2,
		area : [ "400", "45%" ],
		content : rootPath + '/goods/goodsBrand/addOrEdit?goodsBrandId=' + cbox
	});
}

function deleteGoodsBrand() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/goods/goodsBrand/deleteGoodsBrand';
		var result = CommnUtil.ajax_req(url, {
			ids : cbox.join(",")
		}, "json");
		if (result) {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}
	});
}
